// pages/course/course.js
var util = require("../../utils/util.js");

Page({

  /**
   * 页面的初始数据
   */
  data: {
    // navs-bar-begin
    navs: [{
      icon: "5",
      title: "直播",
      url: "../lp/lp"
    },
    {
      icon: "(",
      title: "视频",
      url: "../video/video"
    }, {
      icon: "6",
      title: "音频",
      url: "../music/music"
    }, {
      icon: ")",
      title: "图文",
      url: "../tutorial/tutorial"
    }
    ],
    sorts:["综合排序","销量排序","价格从高到低","价格从低到高","折扣从高到低","折扣从低到高"],
    PackageList: [],
    LiveList: [],
    EduVideoList: [],
    EduVoiceList: [],
    CurrList: [],

    params: {
      Param: { AdaptationType: 0, SortType: 0, PriceType: 0, Subject: 0, ShowIndexNum: 10, PageIndex: 1 },
      Action: 18010
    },
    params2: {
      Param: {
        SearchKey: "",
        InPackeage: 1,
        InLive: 1,
        InEduVideo: 1,
        InEduVoice: 1,
        InCurr: 1,
        PageIndex: 1,
        ShowIndexNum: 5
      },
      Action: 18900
    },

    //navs-bar-end

    //searchResult
    searchResultHidden: true,
    courseListHidden: false


  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var params = this.data.params;
    util.reqMedia(params, function (value) {
      that.setData({
        PackageList: value.PackageList
      });
    });
   
   

    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
   
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  //component-select
  onShowResult: function () {  
    var that = this;
    var params2 = this.data.params2;
    params2.Param.SearchKey = this.selectComponent('#select').onGetSearchKey();
    util.reqMedia(params2, function (value) {
      that.setData({
        PackageList: value.PackageList == null ? [] : value.PackageList,
        LiveList: value.LiveList == null ? [] : value.LiveList,
        EduVideoList: value.EduVideoList == null ? [] : value.EduVideoList,
        EduVoiceList: value.EduVoiceList == null ? [] : value.EduVoiceList,
        CurrList: value.CurrList == null ? [] : value.CurrList,
      });
    });
    this.setData({
      searchResultHidden: false,
      courseListHidden: true
    });

  },
  onPickerChange:function(){
    var index=this.selectComponent('#select').onGetIndex();
    var params = this.data.params;
    params.Param.SortType = index;
    var page = this;
    util.reqMedia(params,function(value){
        page.setData({
          PackageList: value.PackageList
        });
    });
    this.setData({
      searchResultHidden: true,
      courseListHidden: false
    });
  },
  onConfirm:function(){
    var ids = this.selectComponent('#select').onGetIds();
    var params = this.data.params;
    params.Param.AdaptationType = ids.AdaptationType;
    params.Param.PriceType = ids.PriceType;
    params.Param.Subject = ids.Subject;
    var page = this;
    util.reqMedia(params, function (value) {
      page.setData({
        PackageList: value.PackageList
      });
    });
    this.setData({
      searchResultHidden: true,
      courseListHidden: false
    });
  }
})